<?php

namespace App\Sys\Services;


use App\Services\CommonBaseService;


class SysLogService extends CommonBaseService
{
    protected $cache = true;

    protected $cacheBucket = 'SysLog:';

    protected $tokenBucket = 'Token:';

    protected $activeBucket = "Active:";

    const LOG_TYPE_LOGIN = 0; //系统登录日志

    public function saveSysLog($params = [])
    {
        $data = [];
        $data['operation_id'] = empty($params['operation_id']) ? 0 : $params['operation_id'];
        $data['different_content'] = empty($params['different_content']) ? '' : $params['different_content'];
        $data['teble_name'] = empty($params['teble_name']) ? '' : $params['teble_name'];
        $data['log_type'] = empty($params['log_type']) ? 0 : $params['log_type'];
        $data['create_time'] = nowTime();
        $id = $this->model->insertGetId($data);
        return $id;
    }

    public function saveSysLoginLog($userId, $machineInfo)
    {
        $data = [];
        $data['ip'] = getClientIp(1);
        $data['user_id'] = $userId;
        $data['operation_id'] = $userId;
        $data['different_content'] = $machineInfo;
        $data['teble_name'] = 'sys_admin_user';
        $this->saveSysLog($data);
    }
}
